package com.zhaotianhao.check.groupserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhaotianhao.check.groupserver.entity.Group;
import com.zhaotianhao.check.groupserver.entity.GroupVO;
import com.zhaotianhao.check.groupserver.mapper.GroupMapper;
import com.zhaotianhao.check.groupserver.service.IGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 检查组 服务实现类
 * </p>
 *
 * @author Z-7
 * @since 2022-03-29
 */
@Service
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements IGroupService {

    /**
     * @param groupVO
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<Group> getPageInfo(GroupVO groupVO, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        if (!StringUtils.hasText(groupVO.getCondition())) {
            return new PageInfo<>(list());
        }
        // 拼接查询
        QueryWrapper<Group> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("group_coding",groupVO.getCondition())
                .or().like("group_name",groupVO.getCondition())
                .or().eq("mnemonic_code",groupVO.getCondition());
        List<Group> list = baseMapper.selectList(queryWrapper);
        return new PageInfo<>(list);
    }
}
